package com.dd.stack.redis.config.redisConfig.msgListener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/1/30 16:53
 * @Description 消息监听器，用于监听Redis中的消息
 */
@Slf4j
@Component
public class RedisMessageListener implements MessageListener {

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String messageBody = new String(message.getBody());
        log.info("Received message: " + messageBody);
        // 处理消息，例如生成订单
        processOrder(messageBody);
    }

    private void processOrder(String orderData) {
        // 示例：解析订单数据并处理
        log.info("Processing order: " + orderData);
        // 模拟订单生成逻辑
        log.info("Order generated successfully!");
    }
}
